stat_file=/usr/local/etc/.state
if [ -f $stat_file ]; then
echo "DOWNLOADING" > $stat_file
revision_from=`cat /usr/local/etc/.revision`
revision_to=`cat /usr/local/etc/.new_revision`
repository=http://sdk4-custom.googlecode.com/svn/trunk/
target_directory=/usr/local/etc/
diff=/usr/local/etc/.diff
counter_file=/usr/local/etc/.counter
if [ ! -f $counter_file ]; then
if [ -f $diff ]; then
rm -f $diff
fi
if [ "$revision_to" -gt "$revision_from" ]; then
/opt/bin/svn diff --summarize -r$revision_from:$revision_to $repository | grep "^[AM]" >> $diff
counter=`sed -n '$=' $diff`
echo $counter > $counter_file
echo "COUNT_OK" > $stat_file

for line in `cat $diff`
do
    if [ $line != "A" ] && [ $line != "AM" ] && [ $line != "M" ]; then
        filename=`echo "$line" |sed "s|$repository||g"`
        if [ ! -d $target_directory$filename ]; then
            directory=`dirname $filename`
            mkdir -p $target_directory$directory
            /opt/bin/svn export --force -r $revision_to $line $target_directory$filename
                        let counter=counter-1
                        echo $counter > $counter_file
        fi
    fi
done
echo $revision_to > /usr/local/etc/.revision
echo "DOWNLOAD_OK" > $stat_file
rm -f $counter_file
else
echo "ABORT" > $stat_file
fi
fi
rm -f /usr/local/etc/log.xml
fi
